package com.bcu.calculus.controller;

import com.bcu.calculus.entity.*;
import com.bcu.calculus.mapper.SlistMapper;
import com.bcu.calculus.mapper.TlistMapper;
import com.bcu.calculus.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Api(tags = "01  公共数据获取模块")
@RestController
@RequestMapping("/api/PublicInfo")
public class PublicInfoController {

    @Resource
    private SendService sendService;
    @Resource
    private SlistMapper slistMapper;
    @Resource
    private TlistMapper tlistMapper;



    @ApiOperation(value = "根据路由和学期编号获取公共信息")
    @GetMapping(value = "/getRouterAndPublicInfo")
    public Message<?> getRouterAndPublicInfo(SendList sendList){
        return sendService.getRouterAndPublicInfo(sendList.getFlistId(),sendList.getSlistId(),sendList.getTlistId(),sendList.getSendSemseterId());
    }

    @ApiOperation(value = "根据路由和学期编号获取公共信息姓名模糊查询")
    @GetMapping(value = "/getRouterAndPublicInfoName")
    public Message<?> getRouterAndPublicInfoLikeName(SendList sendList){
        return sendService.getRouterAndPublicInfoName(sendList.getFlistId(),sendList.getSlistId(),sendList.getTlistId(),sendList.getSendSemseterId(),sendList.getUserName());
    }


    @ApiOperation(value = "获取当前系统时间")
    @GetMapping(value = "/getSystemTime")
    public Message<Date> getSystemTime(){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        return Message.success("当前系统时间").add(df.format(new Date()));
    }

    @ApiOperation(value = "根据类型获取路由信息(flist表中无type这个字段所以没有)")
    @GetMapping(value = "/getListByType")
    public Message<HashMap> getListByType(Integer type){
        List<Slist> slistList = slistMapper.getSlistByType(type);
        List<Tlist> tlistList = tlistMapper.getSlistIdByType(type);
        HashMap<String,Object> map = new HashMap<>();
        map.put("slist",slistList);
        map.put("tlist",tlistList);
        return Message.success(null).add(map);
    }


}
